package cn.hycat.leetcode.easy;

import java.util.Stack;

/**
 * @author 吕泽浩业
 * @version 1.0
 */
public class L232用栈实现队列 {

}

class MyQueue {
    private Stack<Integer> pushStack;
    private Stack<Integer> popStack;

    public MyQueue() {
        pushStack = new Stack();
        popStack = new Stack();
    }

    public void push(int x) {
        pushStack.push(x);
    }

    public int pop() {
        dao();
        return popStack.pop();
    }

    public int peek() {
        dao();
        return popStack.peek();
    }

    public boolean empty() {
        return pushStack.isEmpty() && popStack.isEmpty();
    }

    //保证取数据时：若pop栈为空，则将push栈全部倒入
    public void dao() {
        if(popStack.isEmpty()) {
            while (!pushStack.isEmpty()) {
                popStack.push(pushStack.pop());
            }
        }
    }
}

class CQueue {
    private Stack<Integer> pushStack;
    private Stack<Integer> popStack;

    public CQueue() {
        pushStack = new Stack();
        popStack = new Stack();
    }

    public void appendTail(int value) {
        pushStack.push(value);
    }

    public int deleteHead() {
        if(pushStack.isEmpty() && popStack.isEmpty())
            return -1;
        else {
            dao();
            return popStack.pop();
        }
    }

    //保证取数据时：若pop栈为空，则将push栈全部倒入
    public void dao() {
        if(popStack.isEmpty()) {
            while (!pushStack.isEmpty()) {
                popStack.push(pushStack.pop());
            }
        }
    }
}